﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Module.Core.BusinessLogic.ProductCart;
using Module.Core.Common;
using Module.Core.EntitiesInfo.TablesInfo;

namespace Web.Cms.ProductCart
{
    public partial class ProductOrderDetails : System.Web.UI.Page
    {

        #region Khai báo biến

        private int orderId;
        #endregion
        protected void Page_Load(object sender, EventArgs e)
        {
            orderId = ObjConvertUtility.ToInt32(Request.QueryString["orderId"]);
            if(!IsPostBack)
            {
                LoadData();
                
            }
        }

        #region LoadData
        private void LoadData()
        {

            DataSet ds;
            ds = ProductOrderDetailsBL.ListProductOrderDetails(orderId);
            if (ds != null)
            {
                DataTable dtbData = ds.Tables[0];
                if (dtbData.Rows.Count > 0)
                {

                    grdProductOrderDetails.DataSource = dtbData;
                    grdProductOrderDetails.DataBind();
                   
                }
            }
        }
        #endregion

        protected void grdProductOrderDetails_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            try
            {
                switch (e.CommandName)
                {
                    case "Commanddelete":
                        try
                        {
                            int orderIdDe = Convert.ToInt32(e.CommandArgument);
                            ProductOrderDetailsBL.Delete(orderIdDe);
                            LoadData();
                        }
                        catch (Exception ex)
                        {
                            lblMessage.Text = ex.Message;
                        }
                        break;
                    default:
                        break;
                }
            }
            catch (Exception ex)
            {
                lblMessage.Text = ex.Message;
            }
        }

        

    }
}